//app.js
App({
  onLaunch: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (e) {
        var a = e.model;
        if (a.indexOf("iPhone") != -1 && a.indexOf("X") != -1) { //是不是包含iphoneX
          that.globalData.isIphoneX = true
        } else {
          that.globalData.isIphoneX = false
        }
      }
    })

    const res = wx.getSystemInfoSync()
    const menuInfo = wx.getMenuButtonBoundingClientRect();
    const { screenHeight, safeArea: { bottom } } = res
    console.log("系统信息是：", res)
    console.log("漂浮小程序信息是：", menuInfo)
    if (screenHeight && bottom){
      this.globalData.safeBottom = (screenHeight - bottom) * (750 / res.windowWidth)
    }
    this.globalData.safeTop = (res.statusBarHeight + menuInfo.height+ (menuInfo.top - res.statusBarHeight)*2) * (750 / res.windowWidth)

    this.globalData.menuTop = menuInfo.top * (750 / res.windowWidth)
    this.globalData.menuHeight=menuInfo.height * (750 / res.windowWidth)


    // 判断登录token是否有效
    let accessTokenData = wx.getStorageSync('accessTokenData')
    let accessToken = accessTokenData.accessToken
    let expiresTime = accessTokenData.expiresTime
    console.log(expiresTime,Date.now() + 1*24*60*60*1000)
    if(expiresTime < (Date.now() + 1*24*60*60*1000)){
      wx.removeStorageSync('accessTokenData')
    }

    // 加载字体
    // wx.loadFontFace({
    //     family: 'PingFang SC',
    //     source: 'url("https://dev.yueyoumap.com/admin/static/PingFangSC.ttf")',
    //     success: res=>{
    //         console.log("加载字体成功！")
    //     }
    // })
  },

  // 权限询问
  getRecordAuth: function() {
    wx.getSetting({
      success(res) {
        console.log("succ")
        console.log(res)
        if (!res.authSetting['scope.record']) {
          wx.authorize({
            scope: 'scope.record',
            success() {
                // 用户已经同意小程序使用录音功能，后续调用 wx.startRecord 接口不会弹窗询问
                console.log("succ auth")
            }, fail() {
                console.log("fail auth")
            }
          })
        } else {
          console.log("record has been authed")
        }
      }, fail(res) {
          console.log("fail")
          console.log(res)
      }
    })

  },

  onHide: function () {
    // wx.stopBackgroundAudio()
  },

  globalData: {
    isIphoneX: false,
    safeBottom: 0,
    safeTop:0,
    tabBarHeight: 116,
    menuTop: 0,
    menuHeight: 0,
    server:"https://dev.yueyoumap.com",
    switchTabFalg: 0,
    history:0,
    activeCourseList:0,
    courseCollectionHotBackgoundList: [
      "linear-gradient(121deg, #07D267 3%, #1CCE9E 100%);",
      "linear-gradient(300deg, #5B80FF 0%, #4F98FF 100%);",
      "#FDB028;",
    ],
    freshUserInfo:false,
  }
})